Ext.ns('AIR2.Source.Contact');
/***************
 * Source Contact Modal - Source Info tab
 *
 * @class AIR2.Source.Contact.Info
 * @extends Ext.form.FormPanel
 * @xtype air2srcconinfo
 * @cfg {Record} record
 * @cfg {Boolean} allowEdit
 *   False to disable editing.  Defaults to true.
 *
 */
AIR2.Source.Contact.Info = function(cfg) {
    var store = cfg.record.store;
    cfg.allowEdit = (cfg.allowEdit === false) ? false : true;
    cfg.items = [{
        xtype: 'fieldset',
        title: 'Primary',
        layout: 'column',
        items: [{
            xtype: 'container',
            columnWidth: .54,
            layout: 'form',
            labelWidth: 76,
            defaults: {width: 138},
            items: [{
                xtype: 'textfield',
                fieldLabel: 'Username',
                name: 'src_username',
                allowBlank: false
            },{
                xtype: 'textfield',
                fieldLabel: 'First Name',
                name: 'src_first_name'
            },{
                xtype: 'textfield',
                fieldLabel: 'Last Name',
                name: 'src_last_name'
            },{
                xtype: 'textfield',
                fieldLabel: 'Middle Initial',
                name: 'src_middle_initial'
            }]
        },{
            xtype: 'container',
            columnWidth: .46,
            layout: 'form',
            labelWidth: 70,
            defaults: {width: 128},
            items: [{
                xtype: 'textfield',
                fieldLabel: 'Pre Name',
                name: 'src_pre_name'
            },{
                xtype: 'textfield',
                fieldLabel: 'Post Name',
                name: 'src_post_name'
            },{
                fieldLabel: 'Status',
                name: 'src_status',
                xtype: 'air2combo',
                width: 130,
                disabled: true,
                choices: [['A', 'Active'], ['F', 'Inactive']]
            },{
                xtype: 'air2button',
                style: 'padding-left: 76px',
                air2type: 'SAVE',
                air2size: 'MEDIUM',
                text: 'SAVE',
                hidden: true,
                scope: this,
                handler: function() {
                    var f = this.getForm();
                    if (f.isValid()) {
                        f.updateRecord(store.getAt(0));
                        var n = store.save();
                        if (n > -1) {
                            store.on('save', function() {
                                f.trackResetOnLoad = true;
                                f.loadRecord(store.getAt(0));
                                this.get(1).update(store.getAt(0).data);
                            }, this, {single:true});
                        }
                    }
                }
            }]
        }]
    },{
        xtype: 'fieldset',
        title: 'More',
        data: cfg.record.data,
        tpl: new Ext.XTemplate(
            '<tpl for=".">' +
              '<p>Created by {[AIR2.Format.userName(values.CreUser, true)]} ' +
                'on {[AIR2.Format.dateLong(values.src_cre_dtim)]}</p>' +
              '<p>Updated by {[AIR2.Format.userName(values.UpdUser, true)]} ' +
                'on {[AIR2.Format.dateLong(values.src_upd_dtim)]}</p>' +
              '<p>Joined via <b>{[AIR2.Format.sourceChannel(values.src_channel)]}</b></p>' +
            '</tpl>',
            {compiled:true, disableFormats:true}
        )
    }];

    // call parent constructor
    cfg.monitorValid = cfg.allowEdit;
    AIR2.Source.Contact.Info.superclass.constructor.call(this, cfg);

    // load the record
    this.getForm().loadRecord(cfg.record);
}
Ext.extend(AIR2.Source.Contact.Info, Ext.form.FormPanel, {
    plain: true,
    padding: '10px 15px 10px 15px',
    layout: 'form',
    monitorValid: true,
    listeners: {
        clientvalidation: function(form, valid) {
            if (!form.saveBtn) {
                form.saveBtn = form.findByType('air2button')[0];
            }
            if (form.getForm().isDirty()) {
                form.saveBtn.show();
            }
            else {
                form.saveBtn.hide();
            }
        }
    }
});
Ext.reg('air2srcconinfo', AIR2.Source.Contact.Info);